﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

public partial class JGGL_JGGLAdd : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!Page.IsPostBack)
    {
      if (!ProjectPrivate.GetQX("4"))
      {
        Server.Transfer("~\\blank.aspx");
      }
      //if (CWSD.GetSDZT())
      //{
      //  Server.Transfer("~\\sd.aspx");
      //}
      string sID = CommonUse.GetID();
      if (!string.IsNullOrEmpty(sID))
        InitData(sID);
      DataSet ds = YQXZ.GetDS();
      CommonUse.BindDDL(ds, "yqxzid", "yqxz", "", ddlYQXZ);
    }
  }

  protected void InitData(string sID)
  {
    SqlDataReader dr = JGGL.GetXX(sID);
    if (dr.Read())
    {
      txtName.Text = dr["JG"].ToString();
      txtJGTJJJ.Text = dr["jj"].ToString();
      txtJGWJ.Text = dr["jgwj"].ToString();
      dateJG.Text = dr["rq"].ToString();
      txtBZ.Text = dr["jgbz"].ToString();
      ddlYQXZ.SelectedValue = dr["yqxzid"].ToString();
      dateJG.Enabled = false;
    }
    dr.Close();
  }

  protected void btnConfirm_Click(object sender, EventArgs e)
  {
    if (string.IsNullOrEmpty(CommonUse.GetID()))
      Insert();
    else
      Update();
  }

  //插入
  protected void Insert()
  {
    if (JGGL.ExistID(dateJG.Text, ddlYQXZ.SelectedValue))
    {
      lbMessage.Text = "此日期已存在价格";
      return;
    }
    string sID = CommonUse.GetID("jcxx_yqjg", "jgid");
    Save(sID);
  }

  protected void Save(string sID)
  {
    List<CommandInfo> cis = new List<CommandInfo>();

    cis.Add(CommonUse.DeleteCI("jcxx_yqjg", "jgid", sID));

    ArrayList arrValue = new ArrayList();
    arrValue.Add(sID);
    arrValue.Add(ddlYQXZ.SelectedValue);
    arrValue.Add(txtName.Text);
    arrValue.Add(dateJG.Text);
    arrValue.Add(txtBZ.Text);
    arrValue.Add(txtJGTJJJ.Text);
    arrValue.Add(txtJGWJ.Text);
    ArrayList arrLengh = new ArrayList();
    arrLengh.Add("20");
    arrLengh.Add("20");
    arrLengh.Add("20");
    arrLengh.Add("20");
    arrLengh.Add("200");
    arrLengh.Add("20");
    arrLengh.Add("200");
    cis.Add(CommonUse.InsertCI("jcxx_yqjg", arrValue, arrLengh));

    if (DbHelperSQL.ExecuteSqlTran(cis) > 0)
    {
      lbMessage.Text = "保存成功";
    }

  }

  //修改
  protected void Update()
  {
    Save(CommonUse.GetID());
  }
}
